<?php
/**
 * category.class.php
 */

class category
{
	var $db;
	var $table;
	var $tablepre;
	
	function __construct()
	{
		global $db, $tablepre;
		$this->db = &$db;
		$this->table = $tablepre.'category';
	}
	
	function category()
	{
		$this->__construct();
	}
	
	function get($cateid)
	{
		if(empty($cateid)) return false;
		$category = $this->db->fetch_first("SELECT * FROM `$this->table` WHERE cid='$cateid'");
		return $category;
	}
	
	function getsubcate($cateid)
	{
		if(empty($cateid)) return false;
		$subcate = $this->db->fetch_all("SELECT cid, cname FROM `$this->table` WHERE fid='$cateid' ORDER BY displayorder");
		
		if(!empty($subcate))
		{
			return $subcate;
		}
		else
		{
			return;
		}
	}
	
	function getlist()
	{
		$cate = $this->db->fetch_all("SELECT * FROM `$this->table` WHERE fid=0 ORDER BY displayorder");

		//取子分类 !!!如果不分开取，排序后，数组的下标发生变化，会数据显示会不正常
		foreach ($cate as $key => $val)
		{
			$subid = $val['cid'];
			$cate[$key]['subcate'] = $this->db->fetch_all("SELECT * FROM `$this->table` WHERE fid='$subid' ORDER BY displayorder");
		}

		return $cate;
	}
}
?>